# Maintainer: Vincent Torri <vincent.torri@gmail.com>

_realname=thorvg
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.15.10
pkgrel=1
pkgdesc="Lightweight vector graphic library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.thorvg.org/'
msys2_repository_url='https://github.com/thorvg/thorvg'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libwebp")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("${msys2_repository_url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('ea4bfda399364d0037b68b7bb50f78769d00cbe9d8ed743e05ae6c50d225c7cc')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --buildtype=release \
      -Ddefault_library=shared \
      -Dloaders=all \
      -Dsavers=all \
      -Dbindings=capi \
      -Dtools=all \
      -Dtests=true \
      ../${_realname}-${pkgver}

  meson compile
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  meson test
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" meson install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
